package com.transaction.handler;

import com.transaction.dao.DeptDao;
import com.transaction.dao.UserDao;
import com.transaction.service.TestService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.concurrent.Executor;

@Service("threadHandler")
public class ThreadHandler {
    public static Log logger = LogFactory.getLog(ThreadHandler.class);
    @Autowired
    private Executor taskAsyncPool;
    @Autowired
    private TestService testService;

    @Transactional(propagation = Propagation.REQUIRES_NEW)
    public void testHandler() {
        taskAsyncPool.execute(new Runnable() {
            @Override
            public void run() {
                logger.info("测试多线程事务任务启动");
                try {
                    testService.selectUser();
                    Thread.sleep(1200000);
                    System.out.println("testHandler线程执行完毕");
                }catch(Exception e) {
                    e.printStackTrace();
                    logger.info("系统异常===="+e);
                }
            }
        });
    }
}
